import Service from '../../core/baseService';

export default class AddressService extends Service {
  constructor(ctx) {
    super(ctx);
    this.model = this.ctx.sassmodel.Address;
  }
  async add(data) {
    const { goods_id, user_id, number } = data;
    const ans: any = await this.ctx.model.Address.findOne({
      where: {
        goods_id,
        user_id,
      },
    });

    let result: any = {};
    if (ans) {
      result = await this.ctx.model.Address
        .update(
          {
            number: ans.number + number,
          },
          { where: { id: ans.id } },
        );
    } else {
      result = await this.ctx.model.Address.create(data);
    }
    return result;
  }
  // async create(data) {
  
  // }


}
